<?php

namespace App\Http\Controllers\Admin;

use App\Http\Model\User;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class IndexController extends CommonController
{
    //登录后台页面
    public function index()
    {
        return view('admin.index');
    }
    //显示版本信息等
    public function info()
    {
        return view('admin.info');
    }
    //更改超级管理员密码
    public function pass()
    {
        if($input=Input::all()){
            $rules=array(
                'password'=>'required |between: 6,20 | confirmed',
            );
            $mes=array(
                'password.required'=>'新密码不能为空',
                'password.between'=>'新密码必须在6-20位',
                'password.confirmed'=>'新密码与确认密码不匹配',
            );
            $validator = Validator::make($input,$rules,$mes);
            if($validator->passes()){
                $user=User::first();
                $_password=Crypt::decrypt($user->user_pass);
//                echo $_password;
                if($input['password_o']!=$_password){
                    return back()->with('errors','原密码错误！');
                }else{
                    $user->user_pass=Crypt::encrypt($input['password']);
                    $user->save();
                    return back()->with('errors','密码修改成功');
                }
            }else{
                return back()->withErrors($validator);
            }



        }else{

            return view('admin.pass');
        }

    }
}
